<?php
namespace Twoir\Service\Info;

use Twoir\Service\BaseInfo;
use Twoir\System\Support\ParamTrait;

/**
 * 信息详情
 *
 * 2024.05.03 cighsen02 3651872575
*/
class Detail extends BaseInfo
{
	use ParamTrait;

	const ALLOW = ['classid', 'id', 'pathid', 'tablename', 'filename'];
	// 当次拉取缓存列表
	private $info;
	/**
	 * 栏目id或表名
	 *
	 * @param string|int $classid
	 */
	public function __construct($classid = null)
	{
		$this->initialize($classid);
	}

	/**
	 * 获取详情
	 *
	 * @param array $add
	 * @return array
	*/
	public function get($add)
	{
		// 过滤无关参数
		$add = $this->paramFilter($add);

		if (empty($add)) throw new \Exception("参数错误!", 9200);

		if (!isset($add['classid']) || empty($add['classid'] = (int)$add['classid'])) {

		    if (!isset($add['tablename']) || empty($add['tablename'])) {

		        throw new \Exception("classid或tablename必要参数", 9200);
		    }
		}

		if (!isset($add['id']) || empty($add['id'] = (int)$add['id'])) throw new \Exception("id必要参数", 9200);

		//定义获取的字段
		$field 	= ['title', 'titleurl','classid','id','newstext','newstime','onclick'];
		$result = $this->getOne(['id' => $add['id']], $field);

		return $this->format($result);
	}
}
